package com.itheima.bean;

import lombok.Data;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
@Data
@EnableConfigurationProperties(CartoonsProperties.class)
public class Cartoon {
    private Cat cat;

    private Mouse mouse;

    private CartoonsProperties cartoonsProperties;

    public Cartoon(CartoonsProperties cartoonsProperties) {
        this.cartoonsProperties = cartoonsProperties;
        cat = new Cat();
        cat.setName(cartoonsProperties.getCat() !=null ?cartoonsProperties.getCat().getName():"tom");
        cat.setAge(cartoonsProperties.getCat() !=null?cartoonsProperties.getCat().getAge():5);
        mouse = new Mouse();
        mouse.setName(cartoonsProperties.getMouse() !=null ?cartoonsProperties.getMouse().getName():"jerry");
        mouse.setAge(cartoonsProperties.getMouse() !=null?cartoonsProperties.getMouse().getAge():8);
    }


    void play(){
        System.out.println(cat.getAge()+"岁的"+cat.getName()+"和"+ mouse.getAge()+"岁的"+mouse.getName()+"打架");
    }
}
